<?php
class StoreManageAction extends CommonAction{
	public function _filter(&$map){
		$map['removed']=1;
	}

public function _before_index() {
		$model = M ( "StoreManage" );
		$list = $model->getField ( 'id,whp,stock,lpm,we,tw,rw,product');
		$this->assign ( 'groupList', $list );
	}
	public function read(){
		$id=$_REQUEST['id'];
		$model = M ( "StoreManage" );
		$vo=$model->where('id='.$id)->find();
		$this->assign ( 'vo', $vo );
		$this->display();
		
	}
	public function _before_add() {
		$model = M ( "StoreManage" );
		$list = $model->select ();
		$this->assign ( 'list', $list );
		$Goods=M('Goods');
		$goodslist=$Goods->select();
		$this->assign('goods',$goodslist);
		$User=M("User");
		$userlist=$User->select();
		$this->assign('user',$userlist);
		
	}
	public function _before_edit() {
		$Goods=M('Goods');
		$goodslist=$Goods->select();
		$this->assign('goods',$goodslist);
		$User=M("User");
		$userlist=$User->select();
		$this->assign('user',$userlist);
	}
	public function _before_insert() {
		$model = M ( "StoreManage" );
		$storename=$_REQUEST['storename'];
	    $StoreManage = $model->where('storename=\''.$storename.'\' and product=\''.$_POST ['product'].'\'')->select();	   
		if($StoreManage[0]['removed']==2){
			$model->where('id='.$StoreManage[0]['id'])->delete();
		}else{
			$this->error ('该 商品名称 已经存在!');
		}
	}
	public function _before_update(){
		$model = M ( "StoreManage" );
		$StoreManage = $model->find ( $_POST ['id'] );
		if ($StoreManage ['product'] != $_POST ['product']) {
			$map['product'] = $_POST ['product'];
			//$map['removed'] = 1;
			$map['storename'] = $StoreManage['storename'];
			$result = $model->where ($map)->select ();
			if ($result) {
				if($result[0]['removed']==2){
					$model->where('id='.$result[0]['id'])->delete();
				}else{
					$this->error('该 商品名称 已经存在!');
				}
			}
		}
	}
	
	public function storeA(){
		$model=M('StoreManage');
		import ( '@.Org.Page' );
		$count = $model->where("storename='storeA' and removed=1")->count ();
		$page = new Page ( $count, ! empty ( $_REQUEST ['numPerPage'] ) ? $_REQUEST ['numPerPage'] : 24 );
		$pageNum = ! empty ( $_REQUEST ['pageNum'] ) ? $_REQUEST ['pageNum'] : 1;
		$list = $model->where("storename='storeA' and removed=1")->page ( $pageNum . "," . $page->listRows )->order('id desc')->select ();
		$page->setConfig('header','条');
		$page->setConfig('first','首页');
		$page->setConfig('last','尾页');
		$page->setConfig('theme', "<div data-role='button' data-theme='a'>共%totalRow%  %header%  第%nowPage%/%totalPage% 页   %upPage% %downPage% %first%    %linkPage%   %end%</div>");
		//分页显示
		$page = $page->show ();
		//如果信息过长，则简略显示
		foreach ( $list as $key => $value ) {
			$length = strlen ( $value ['content'] );
			if ($length > 18) {
				$value ['content'] = substr ( $value ['content'], 0, 15 ) . '......';
				$list [$key] = $value;
			}
		}
			
		$this->assign('list',$list);
		$this->assign ( 'totalCount', $count ); // 总条数
		$this->assign ( 'numPerPage', $page->listRows ); // 每页显示的条数
		$this->assign ( 'currentPage', $pageNum ); // 当前页
		$this->assign('page',$page);
		$this->display();
	}
	public function storeB(){
		$model=M('StoreManage');
		import ( '@.Org.Page' );
		$count = $model->where("storename='storeB' and removed=1")->count ();
		$page = new Page ( $count, ! empty ( $_REQUEST ['numPerPage'] ) ? $_REQUEST ['numPerPage'] : 24 );
		$pageNum = ! empty ( $_REQUEST ['pageNum'] ) ? $_REQUEST ['pageNum'] : 1;
		$list = $model->where("storename='storeB' and removed=1")->page ( $pageNum . "," . $page->listRows )->order('id desc')->select ();
			$page->setConfig('header','条');
		$page->setConfig('first','首页');
		$page->setConfig('last','尾页');
		$page->setConfig('theme', "<div data-role='button' data-theme='a'>共%totalRow%  %header%  第%nowPage%/%totalPage% 页   %upPage% %downPage% %first%    %linkPage%   %end%</div>");
		//分页显示
		$page = $page->show ();
		//如果信息过长，则简略显示
		foreach ( $list as $key => $value ) {
			$length = strlen ( $value ['content'] );
			if ($length > 18) {
				$value ['content'] = substr ( $value ['content'], 0, 15 ) . '......';
				$list [$key] = $value;
			}
		}
			
		$this->assign('list',$list);
		$this->assign ( 'totalCount', $count ); // 总条数
		$this->assign ( 'numPerPage', $page->listRows ); // 每页显示的条数
		$this->assign ( 'currentPage', $pageNum ); // 当前页
		$this->assign('page',$page);
		$this->display();
	}
	public function storeC(){
		$model=M('StoreManage');
		import ( '@.Org.Page' );
		$count = $model->where("storename='storeC' and removed=1")->count ();
		$page = new Page ( $count, ! empty ( $_REQUEST ['numPerPage'] ) ? $_REQUEST ['numPerPage'] : 24 );
		$pageNum = ! empty ( $_REQUEST ['pageNum'] ) ? $_REQUEST ['pageNum'] : 1;
		$list = $model->where("storename='storeC' and removed=1")->page ( $pageNum . "," . $page->listRows )->order('id desc')->select ();
		$page->setConfig('header','条');
		$page->setConfig('first','首页');
		$page->setConfig('last','尾页');
		$page->setConfig('theme', "<div data-role='button' data-theme='a'>共%totalRow%  %header%  第%nowPage%/%totalPage% 页   %upPage% %downPage% %first%    %linkPage%   %end%</div>");
		//分页显示
		$page = $page->show ();
		//如果信息过长，则简略显示
		foreach ( $list as $key => $value ) {
			$length = strlen ( $value ['content'] );
			if ($length > 18) {
				$value ['content'] = substr ( $value ['content'], 0, 15 ) . '......';
				$list [$key] = $value;
			}
		}
			
		$this->assign('list',$list);
		$this->assign ( 'totalCount', $count ); // 总条数
		$this->assign ( 'numPerPage', $page->listRows ); // 每页显示的条数
		$this->assign ( 'currentPage', $pageNum ); // 当前页
		$this->assign('page',$page);
		$this->display();
	}
	
}
	


?>
